package ThreadPool.test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 懒加载方式线程安全测试类
 * @date 2022/12/18 18:26
 */


class ObjectTest {

    public ObjectTest() {
        System.out.println(this);
    }
}

public class LazyInitRace {



    static ObjectTest createObject(){
        ObjectTest object = null;
        if(null == object){
            object = new ObjectTest();

        }
        return object;
    }

    public static void main(String[] args) {

        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
           executorService.execute(LazyInitRace::createObject);
        }
        executorService.shutdown();

    }


}
